package com.java.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.java.model.*;
import com.java.service.*;
import com.java.utils.CommonUtils;
import com.java.utils.JsonBody;
import com.java.utils.PageList;
import com.java.utils.ResponseUtil;;

@RestController
@RequestMapping("/thingtype")
public class ThingTypeController {
	private ThingTypeService thingtypeService;

	public ThingTypeService getThingTypeService() {
		return thingtypeService;
	}

	@Autowired
	public void setThingTypeService(ThingTypeService thingtypeService) {
		this.thingtypeService = thingtypeService;
	}

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("add")
	public JsonBody add(@RequestBody ThingType nt) {

			int r=0;
			if(nt.getId()==0)
				r = thingtypeService.Add(nt);
			else
				r=thingtypeService.Edit(nt);
			if(r>0)
				return Util.SetMap("保存成功", true);
			else
				return
						Util.SetMap("保存失败", false);
	}

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("getbyid")
	public JsonBody getbyid(int id) {
		return Util.SetData(thingtypeService.GetByID(id));
	}

	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("list")
	public JsonBody list() {
		return Util.SetData(thingtypeService.Get());
	}




	@CrossOrigin(origins = "*")
	@ResponseBody
	@RequestMapping("del")
	public JsonBody Del(int id) {
		if(thingtypeService.Del(id)>0)
			return Util.SetMap("删除成功", true);
		else
			return Util.SetMap("删除失败", false);
	}


}
